#     Xepec.ru - социальная сеть
#     Copyright (C) 2008  Fedorchenko Alexander <admin@xepec.ru>
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: <admin@xepec.ru>
#     Date: 06/02/2010
#
#
# Страница просмотра учетки пользователя
# с выбором настроек, если этот пользователь вы
# и с просмотров проебаных вами (не им) событиями (новостями)

#require "../config.pl";
require "../core.pl";
require "lib_video.pl";

$auth_id = do_check();

&get_query;
$act=$queryString{ "act" };
#$video_id=1;
$video_id=$queryString{ "video_id" };


##################################################################
##################-Правельный вариант-############################
##################################################################
$uname_get=$queryString{ "uname" };                   ########
if (defined($uname_get))                                ####
{                                                       ####
	if ($uname_get != $auth_id)                     ####
	{                                               ####
		$masha=0;                               ####
	}                                               ####
	else						####
	{						####
		$masha=1;				####
	}						####
	$uname_id=$uname_get;                           ####
}                                                       ####
else                                                    ####
{                                                       ####
	$masha=1;                                       ####
	print "Location: ?uname=".$auth_id."\n\n";      ####
	#exit();						####
	$uname_id=$auth_id;                             ####
}                                                       ####
@uname = uname_get($uname_id);                        ########
#################################################################
#################################################################
#################################################################
#используется в /litera/index.pl, /musik/index.php||pl, /groups/index.pl

#print $masha."\n\n\n\n\n";
if(!$auth_id) {print "Location: $SITE_ADDR/join.pl\n\n"; exit();};
if($act eq "exit")
{
		$xepec_nic_cookie = "xepec_nic 0 +3";
		$xepec_pass_cookie = "xepec_pass 0 +3";
		set_cookie($xepec_nic_cookie,$xepec_pass_cookie);
 		print "Location: $SITE_ADDR/\n\n";
}
if(!$act) {$act="videolist";}
#if(($act eq 'play') and !$video_id )
if($act eq 'play' and !$video_id){$act="videolist";}

if(($masha==1) and (video_count($auth_id)==0) and ($act eq "pl")) {$act="add";}


###############################################################################################################################
#----------------------------------------------Вывод на экран информации------------------------------------------------------#
###############################################################################################################################

print "Content-type: text/xml; charset=utf-8\n\n";
print qq{<?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/xsl" href="./video.xsl"?>
<document>
    <user id="@uname['0']" nic="@uname['3']" />
    <site_name>$SITE_NAME</site_name>
    <site_name2>$SITE_NAME2</site_name2>
    <title>$SITE_NAME :: @uname['1']</title>
    <version>$VERSION</version>
    <message>TRUE</message>
};
do_print_menu();
#$act='add-ok';
use Switch;
switch ($act)
{
	case "play"
	{	
		print qq{
		<subnav>
			<object>
				<name>Плэйлист</name>
				<href>index.pl?uname=$auth_id&amp;act=videolist</href>
			</object>
			<object class="child">
				<name>Добавить фаил</name>
				<href>index.pl?uname=$auth_id&amp;act=add</href>
			</object>
			<object class="child">
				<name>Скачать</name>
				<href>index.pl?uname=$auth_id&amp;act=dl</href>
			</object>
			<object>
				<name>Уйти из системы</name>
				<href>index.pl?uname=$auth_id&amp;act=exit</href>
			</object>
		</subnav>
		<dd>
		};
		use Ogg::Vorbis::Header;
	#read_tag("/01.ogg");
		print qq{
		</dd>
			<content type=\"username\">
				<data>
					<play>};
						@arr_video = db_tag_read($video_id);
						print qq{<item id="$video_id" url="/usr/@arr_video[1]/video/$video_id.ogg" title="@arr_video[2]" artist="$arr_video[3]" year="$arr_video[4]" ganre="$arr_video[5]" />};
		print qq{		</play>
				</data>
			</content>
			};
	}
	case "videolist"
	{
		print qq{
		<subnav>
			<object>
				<name>Видео-лист</name>
				<href>index.pl?uname=$auth_id&amp;act=videolist</href>
			</object>
			<object class="child">
				<name>Добавить фаил</name>
				<href>index.pl?uname=$auth_id&amp;act=add</href>
			</object>	
			<object>
				<name>Выход</name>
				<href>index.pl?uname=$auth_id&amp;act=exit</href>
			</object>
		</subnav>
		};
		
		print qq{
			<content type=\"video-list\">
				<data>
					<videolist>};
						print_list_videos_xml_tags($uname_id);
		print qq{		</videolist>
				</data>
			</content>
			};
		if ($masha==1)
		{
			
		}
		else 
		{
			$error = "Нельзя редактировать эту учетную запись";
		}
 	}
	case "add"
 	{
		mkdir("$DOC_ROOT/usr/$auth_id/video",$PREM_CHMOD) || "Error: $!";
		
		print qq{
		<subnav>
			<object>
				<name>Плэйлист</name>
				<href>index.pl?uname=$auth_id&amp;act=videolist</href>
			</object>
			<object class="child">
				<name>Добавить фаил</name>
				<href>index.pl?uname=$auth_id&amp;act=add</href>
			</object>	
			<object>
				<name>Выход</name>
				<href>index.pl?uname=$auth_id&amp;act=exit</href>
			</object>
		</subnav>
		};
		print qq{
			<content type="username">
				<data>
					<add>};
		print qq{		</add>
				</data>
			</content>
			};
		
 	}
	case "add-ok"
 	{
 		$file_upload = file_save("filename");
		print qq{<test dfd="$file_upload" />};
		#if ()
		#{
			
			@arr = db_tag_read($file_upload);
			print qq{
			<content type=\"username\">
				<data>
					<add-ok>};
						print qq{<item id="@arr[0]" title="@arr[2]" artist="$arr[3]" album="@arr[4]" year="$arr[5]" ganre="$arr[6]" track="$arr[7]" />};
			print qq{	</add-ok>
					</data>
				</content>
				};
		#}
		#else
		#{
	#		print qq{
	#		<content type=\"username\">
	#			<data>
	#				<add-err>};
	#					print qq{<item id="111" title="test" artist="3" album="4" year="5" ganre="5" track="5" />};
	#		print qq{	</add-err>
	#				</data>
	#			</content>
	#			};
	#	}
	}
	case "ready"
 	{
		use CGI;
		my $cgi = new CGI;
		
		my $title = $cgi->param("title");
		my $artist = $cgi->param("artist");
		my $album = $cgi->param("album");
		my $year = $cgi->param("year");
		my $ganre = $cgi->param("ganre");
		my $track = $cgi->param("track");
		
		## id-шник песни взяли в начале скрипта по методу GET
		if (db_tag_edit($id,$title,$artist,$album,$year,$ganre,$track))
		{
			@arr = db_tag_read($file_upload);
			print qq{
			<content type=\"username\">
				<data>
					<ready>};
						print qq{<item id="$id" title="$title" artist="$artist" album="$album" year="$year" ganre="$ganre" track="$track" />};
			print qq{	</ready>
					</data>
				</content>
				};
		}
		else
		{
			print qq{
			<content type=\"username\">
				<data>
					<add-err>};
						print qq{<item id="$id" title="$title" artist="0" album="0" year="0" ganre="0" track="0" />};
			print qq{	</add-err>
					</data>
				</content>
				};
		}
	}
}
print qq{</document>};
